
package com.tools.cleanmaster.ui.activity;

import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.tools.ad.util.StatusBarUtil;
import com.tools.cleanmaster.CleanConstant;
import com.tools.cleanmaster.R;
import com.tools.cleanmaster.manager.RatingDialogManager;
import com.tools.cleanmaster.ui.base.SingleActivity;
import com.tools.cleanmaster.ui.view.header.HeadHelper;

public class AboutActivity extends SingleActivity implements OnClickListener {
    private static final String TAG = "AboutActivity";

    private TextView mTermOfUse;
    private TextView mPrivacyPolicy;

    private static int mDeveloperCount;


    @Override
    protected void onCreate(android.os.Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initViews();
    }

    private void initViews() {
        setContentView(R.layout.activity_about);
        StatusBarUtil.setColor(this, getResources().getColor(R.color.common_background_blue), 0);
        HeadHelper.setupMainHeader(this, R.id.titlebar, R.string.opda_global_about, this).hideSettingButton().setBackgroundColor();

        //使用协议
        mTermOfUse = findViewById(R.id.tv_term_of_use);
        //隐私条款
        mPrivacyPolicy = findViewById(R.id.tv_privacy_policy);

        mTermOfUse.setOnClickListener(this);
        mPrivacyPolicy.setOnClickListener(this);

        TextView mTvVersion = findViewById(R.id.about_us_version);
        CharSequence version = mTvVersion.getText();
        try {
            String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
            mTvVersion.setText(version + versionName);
        } catch (NameNotFoundException e) {
            mTvVersion.setVisibility(View.GONE);
        }

        findViewById(R.id.icon).setOnClickListener(this);
        findViewById(R.id.hide).setOnClickListener(this);
        findViewById(R.id.tv_rate).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v == mTermOfUse) {
            //使用协议
            Intent intent = new Intent();
            intent.putExtra(CleanConstant.CLAUSE_HTML_NAME, getString(R.string.term_of_use_html));
            intent.setClass(this, HelperActivity.class);
            startActivity(intent);
        } else if (v == mPrivacyPolicy) {
            //隐私条款
            Intent intent = new Intent();
            intent.putExtra(CleanConstant.CLAUSE_HTML_NAME, getString(R.string.privacy_policy_html));
            intent.setClass(this, HelperActivity.class);
            startActivity(intent);
        } else if (v.getId() == R.id.hide || v.getId() == R.id.icon) {
            mDeveloperCount++;
            if (mDeveloperCount >= 10) {
                imContext.handleMobEmptyMessage(R.id.msg_cleaner_develop_mode_enable);
                Log.i("Cleaner", "--  enable  --");
            }
        } else if (v.getId() == R.id.tv_rate) {
            RatingDialogManager.getInstance().showRatingDialog(AboutActivity.this);
        }
    }
}
